<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ include file="include.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ include file="menu.jsp"%>
<div id="categories">
    Имеющиеся приложения
    <table border="1">
        <tr>
            <td>Приложение</td>
            <td>Описание</td>
            <td>Категория</td>
            <td>Статус</td>
        </tr>
        <c:forEach items="${cats}" var="c">
            <c:forEach items="${c.applications}" var="a">
                <tr>
                    <td><c:out value="${a.applicationName}"/></td>
                    <td><c:out value="${a.description}"/></td>
                    <td><c:out value="${a.category.categoryName}"/></td>
                    <td><c:out value="${a.status.statusName}"/></td>

                    <c:url var="editUrl" value="/admin/createApplication.htm">
                        <c:param name="action" value="edit"/>
                        <c:param name="applicationId" value="${a.applicationId}"/>
                    </c:url>
                    <td><a href="${editUrl}">Редактировать</a></td>

                    <c:url var="deleteUrl" value="/admin/deleteApplication.htm">
                        <c:param name="action" value="delete"/>
                        <c:param name="applicationId" value="${a.applicationId}"/>
                    </c:url>
                    <td><a href="${deleteUrl}">Удалить</a></td>
                </tr>

            </c:forEach>
        </c:forEach>
    </table>
</div>

<form:form method="POST" commandName="newApplication" action="createApplication.htm">
    <table style="width:800px">
        <tr>
            <td>Имя приложения</td>
            <td>
                <form:input path="applicationName"/>
            </td>
            <td><form:errors path="applicationName" cssStyle="color:red"/></td>
        </tr>
        <tr>
            <td>Описание</td>
            <td>
                <form:textarea path="description" rows="5" cols="30"></form:textarea>
            </td>
            <td><form:errors path="description" cssStyle="color:red;"/></td>
        </tr>

        <tr>
            <td>Категория</td>
            <td>
                <form:select path="category" cssStyle="width:400px">
                    <form:options items="${cats}" itemValue="categoryName" itemLabel="categoryName"/>
                </form:select>
            </td>
            <td><form:errors path="category" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Статус</td>
            <td>
                Активно : <form:radiobutton path="status" value="active"/><br>
                Неактивно : <form:radiobutton path="status" value="inactive"/>
            </td>
            <td><form:errors path="status" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="submit"></td>
            <td></td>

        </tr>
    </table>

</form:form>